#include "threadPool.h"
int tcpInit(const char *ip,const char *port,int *psockfd)
{
    // ./server 192.168.187.128 1234 4
   *psockfd = socket(AF_INET,SOCK_STREAM,0);
    int reuse = 1;
    int ret = setsockopt(*psockfd,SOL_SOCKET,SO_REUSEADDR,&reuse,sizeof(reuse));
    ERROR_CHECK(ret,-1,"setsockopt");
    // 初始化
    struct sockaddr_in serveraddr;
    serveraddr.sin_family = AF_INET;
    serveraddr.sin_port = htons(atoi(port));
    serveraddr.sin_addr.s_addr = inet_addr(ip);

    // 将socket与ip及port绑定
    ret = bind(*psockfd,(struct sockaddr *)&serveraddr,sizeof(serveraddr));
    ERROR_CHECK(ret,-1,"bind");
    // 监听，将socket转换为被动状态，内部数据结构由发送和接收池转换为半连接和连接池
    listen(*psockfd,50);
    return 0;
}
